package conversions

import (
	"jvmgo/instructions/base"
	"jvmgo/rtda"
)

type L2I struct {
	base.NoOperandsInstruction
}

// The value on the top of the operand stack must be of type long. It is popped from the operand stack and converted to an int result by taking the low-order 32 bits of the long value and discarding the high-order 32 bits. The result is pushed onto the operand stack.
func (self *L2I) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	v := stack.PopLong()
	r := int32(v | 0x00ff)
	stack.PushInt(r)
}

type L2F struct {
	base.NoOperandsInstruction
}

func (self *L2F) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	v := stack.PopLong()
	r := float32(v)
	stack.PushFloat(r)
}

type L2D struct {
	base.NoOperandsInstruction
}

func (self *L2D) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack()
	v := stack.PopLong()
	stack.PushDouble(float64(v))
}
